/**   
 * @Title: AuthorizeReceiver.java 
 * @author 6335yz   
 * @date 2015年9月15日 下午3:01:52 
 */
package com.shanghaionstar.login;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.onstar.cn.auth.AuthPinTokenEntity;
import com.onstar.cn.auth.AuthTokenRequestEntity;
import com.onstar.cn.common.util.Constants;
import com.onstar.cn.framework.mvp.base.core.AppScheduler;
import com.shanghaionstar.login.service.AuthorService;
import com.shanghaionstar.utils.AuthorUtil;
import com.shanghaionstar.utils.BusinessUtil;

import rx.functions.Action1;

/**
 * @ClassName: AuthorizeReceiver
 * @Description: 用于接收定时触发refresh token
 * @author 6335yz
 * @date 2015年9月15日 下午3:01:52
 */
public class AuthorizeReceiver extends BroadcastReceiver {

	/**
	 * (non-Javadoc)
	 * <p>
	 * Title: onReceive
	 * </p>
	 * <p>
	 * Description:
	 * </p>
	 * 
	 * @param context
	 * @param intent
	 * @see BroadcastReceiver#onReceive(Context,
	 *      Intent)
	 */
	@Override
	public void onReceive(Context context, Intent intent) {
		if (intent.getAction().equals(Constants.AUTHORIZE_REFRESH_TOKEN)) {
			AuthorUtil.getInstance().setIsLoginOut(true);
			AuthTokenRequestEntity entity = BusinessUtil.createAuthTokenRequestEntity();
			AuthorService authorService = new AuthorService(context);
			authorService.pinReauthForNoPin(entity).subscribeOn(new AppScheduler().backgroundThread())
					.observeOn(new AppScheduler().mainThread()).subscribe(new Action1<AuthPinTokenEntity>() {
				@Override
				public void call(AuthPinTokenEntity authPinTokenEntity) {
					//执行成功请求，预留
				}
			}, new Action1<Throwable>() {
				@Override
				public void call(Throwable throwable) {

				}
			});
		}
	}
}
